(function(){"use strict";BX.namespace("BX.Landing");var e=BX.Landing.Utils.escapeText;var t=BX.Landing.Utils.Matchers.headerTag;var n=BX.Landing.Utils.changeTagName;var i=BX.Landing.Utils.textToPlaceholders;BX.Landing.Block.Node.Text=function(e){BX.Runtime.loadExtension("landing.node.text.tableeditor");BX.Landing.Block.Node.apply(this,arguments);this.type="text";this.tableBaseFontSize="22";this.onClick=this.onClick.bind(this);this.onPaste=this.onPaste.bind(this);this.onDrop=this.onDrop.bind(this);this.onInput=this.onInput.bind(this);this.onKeyDown=this.onKeyDown.bind(this);this.onMousedown=this.onMousedown.bind(this);this.onMouseup=this.onMouseup.bind(this);this.node.addEventListener("mousedown",this.onMousedown);this.node.addEventListener("click",this.onClick);this.node.addEventListener("paste",this.onPaste);this.node.addEventListener("drop",this.onDrop);this.node.addEventListener("input",this.onInput);this.node.addEventListener("keydown",this.onKeyDown);document.addEventListener("mouseup",this.onMouseup)};BX.Landing.Block.Node.Text.currentNode=null;BX.Landing.Block.Node.Text.prototype={__proto__:BX.Landing.Block.Node.prototype,superClass:BX.Landing.Block.Node.prototype,constructor:BX.Landing.Block.Node.Text,onAllowInlineEdit:function(){this.node.setAttribute("title",e(BX.Landing.Loc.getMessage("LANDING_TITLE_OF_TEXT_NODE")))},onChange:function(e,t){this.superClass.onChange.call(this,t);if(!e){BX.Landing.UI.Panel.EditorPanel.getInstance().adjustPosition(this.node)}if(!t){BX.Landing.History.getInstance().push()}},onKeyDown:function(e){if(e.code==="Backspace"){this.onBackspaceDown(e)}this.onInput(e)},onInput:function(e){clearTimeout(this.inputTimeout);var t=e.keyCode||e.which;if(!(t===90&&(top.window.navigator.userAgent.match(/win/i)?e.ctrlKey:e.metaKey))){this.inputTimeout=setTimeout(function(){if(this.lastValue!==this.getValue()){this.onChange(true);this.lastValue=this.getValue()}}.bind(this),400)}if(this.isTable(e)){var n=parseInt(window.getComputedStyle(e.srcElement).getPropertyValue("font-size"));if(e.srcElement.textContent===""&&e.srcElement.classList.contains("landing-table-td")&&n<this.tableBaseFontSize){e.srcElement.classList.add("landing-table-td-height")}else{e.srcElement.classList.remove("landing-table-td-height")}}},onEscapePress:function(){if(this.isEditable()){if(this===BX.Landing.Block.Node.Text.currentNode){BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}this.disableEdit()}},onDrop:function(e){e.preventDefault()},onPaste:function(e){e.preventDefault();if(e.clipboardData&&e.clipboardData.getData){var t=e.clipboardData.getData("text/plain");var n=BX.Text.encode(t);if(this.isLinkPasted(t)){n=this.prepareToLink(n)}var i=n.replace(new RegExp("\n","g"),"<br>");document.execCommand("insertHTML",false,i)}else{var a=window.clipboardData.getData("text");document.execCommand("paste",true,BX.Text.encode(a))}this.onChange()},onDocumentClick:function(e){if(this.isEditable()&&!this.fromNode){BX.Landing.UI.Panel.EditorPanel.getInstance().hide();this.disableEdit()}this.fromNode=false},onMousedown:function(e){if(!this.manifest.group){this.fromNode=true;if(this.manifest.allowInlineEdit!==false&&BX.Landing.Main.getInstance().isControlsEnabled()){e.stopPropagation();this.enableEdit();if(this.isTable(e)){this.disableEdit();BX.Landing.Block.Node.Text.currentNode.node.querySelectorAll(".landing-table-container").forEach((function(e){if(!e.hasAttribute("table-prepare")){BX.Landing.Block.Node.Text.prototype.prepareNewTable(e)}}));var t=parseInt(window.getComputedStyle(e.srcElement).getPropertyValue("font-size"));if(e.srcElement.textContent===""&&e.srcElement.classList.contains("landing-table-td")&&t<this.tableBaseFontSize){e.srcElement.classList.add("landing-table-td-height")}else{e.srcElement.classList.remove("landing-table-td-height")}}else{if(!this.manifest.textOnly&&!BX.Landing.UI.Panel.StylePanel.getInstance().isShown()){BX.Landing.UI.Panel.EditorPanel.getInstance().show(this.node,null,this.buttons)}if(BX.Landing.Block.Node.Text.nodeTableContainerList){BX.Landing.Block.Node.Text.nodeTableContainerList.forEach((function(e){e.tableEditor.unselect(e.tableEditor)}))}}BX.Landing.UI.Tool.ColorPicker.hideAll()}requestAnimationFrame((function(){if(e.target.nodeName==="A"||e.target.parentElement.nodeName==="A"){var t=document.createRange();t.selectNode(e.target);window.getSelection().removeAllRanges();window.getSelection().addRange(t)}}))}},onMouseup:function(){setTimeout(function(){this.fromNode=false}.bind(this),10)},onClick:function(e){if(this.isTable(e)){this.addTableButtons(e)}e.stopPropagation();e.preventDefault();this.fromNode=false;if(e.target.nodeName==="A"||e.target.parentElement.nodeName==="A"){var t=document.createRange();t.selectNode(e.target);window.getSelection().removeAllRanges();window.getSelection().addRange(t)}},isEditable:function(){return this.node.isContentEditable},enableEdit:function(){var e=BX.Landing.Block.Node.Text.currentNode;if(e){var t=BX.Landing.Block.Node.Text.currentNode.node;var n=t.querySelectorAll(".landing-table-container");if(n.length>0){n.forEach((function(e){if(!e.tableEditor){e.tableEditor=new BX.Landing.Node.Text.TableEditor.default(e)}}));BX.Landing.Block.Node.Text.nodeTableContainerList=n}}if(!this.isEditable()&&!BX.Landing.UI.Panel.StylePanel.getInstance().isShown()){if(this!==BX.Landing.Block.Node.Text.currentNode&&BX.Landing.Block.Node.Text.currentNode!==null){BX.Landing.Block.Node.Text.currentNode.disableEdit()}BX.Landing.Block.Node.Text.currentNode=this;this.buttons=[];this.buttons.push(this.getDesignButton());if(BX.Landing.Main.getInstance()["options"]["allow_ai_text"]){this.buttons.push(this.getAiTextButton())}if(this.isHeader()){this.buttons.push(this.getChangeTagButton());this.getChangeTagButton().onChangeHandler=this.onChangeTag.bind(this)}this.lastValue=this.getValue();this.node.contentEditable=true;this.node.setAttribute("title","")}},getDesignButton:function(){if(!this.designButton){this.designButton=new BX.Landing.UI.Button.Design("design",{html:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DESIGN"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DESIGN")},onClick:function(){BX.Landing.UI.Panel.EditorPanel.getInstance().hide();this.disableEdit();this.onDesignShow(this.manifest.code)}.bind(this)})}return this.designButton},getAiTextButton:function(){if(!this.aiTextButton){this.aiTextButton=new BX.Landing.UI.Button.AiText("ai_text",{html:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_AI_TEXT"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_AI_TEXT")},onClick:function(){BX.Landing.UI.Panel.EditorPanel.getInstance().hide();let e=BX.Landing.Main.getInstance()["options"]["blocks"];let t=this.manifest.sections;let n="";let i={};for(let a=0,s=t.length;a<s;a++){let s=t[a];if(e[s]&&e[s]["meta"]){if(e[s]["meta"]["ai_text_placeholder"]){n=e[s]["meta"]["ai_text_placeholder"]}if(e[s]["meta"]["ai_text_max_tokens"]){i["max_tokens"]=parseInt(e[s]["meta"]["ai_text_max_tokens"])}}}if(!this.aiTextPicker){let e=BX.Landing.Main.getInstance()["options"]["site_id"];let t=top.BX.AI?top.BX.AI.Picker:BX.AI.Picker;this.aiTextPicker=new t({moduleId:"landing",contextId:"text_site_"+e,analyticLabel:"landing_text",history:true,onSelect:function(e){this.node.innerHTML=e.data.replace(/(\r\n|\r|\n)/g,"<br>");this.onChange()}.bind(this),onTariffRestriction:function(){BX.UI.InfoHelper.show("limit_sites_TextAssistant_AI")}});this.aiTextPicker.setLangSpace(BX.AI.Picker.LangSpace.text)}this.aiTextPicker.setEngineParameters(i);this.aiTextPicker.text()}.bind(this)})}return this.aiTextButton},disableEdit:function(){if(this.isEditable()){this.node.contentEditable=false;if(this.lastValue!==this.getValue()){this.onChange();this.lastValue=this.getValue()}if(this.isAllowInlineEdit()){this.node.setAttribute("title",e(BX.Landing.Loc.getMessage("LANDING_TITLE_OF_TEXT_NODE")))}}},getField:function(){if(!this.field){this.field=new BX.Landing.UI.Field.Text({selector:this.selector,title:this.manifest.name,content:this.node.innerHTML,textOnly:this.manifest.textOnly,bind:this.node});if(this.isHeader()){this.field.changeTagButton=this.getChangeTagButton()}}else{this.field.setValue(this.node.innerHTML);this.field.content=this.node.innerHTML}return this.field},setValue:function(e,t,n){this.preventSave(t);this.lastValue=this.isSavePrevented()?this.getValue():this.lastValue;this.node.innerHTML=e;this.onChange(false,n)},getValue:function(){if(this.node.querySelector(".landing-table-container")!==null){const e=this.node.cloneNode(true);this.prepareTable(e);return i(e.innerHTML)}return i(this.node.innerHTML)},isHeader:function(){return t.test(this.node.nodeName)},isTable:function(e){var t=false;if(BX.Landing.Block.Node.Text.currentNode&&e){BX.Landing.Block.Node.Text.currentNode.node.querySelectorAll(".landing-table-container").forEach((function(n){if(n.contains(e.srcElement)){t=true}}))}return t},prepareNewTable:function(e){e.querySelectorAll("br").forEach((function(e){e.remove()}));e.setAttribute("table-prepare","true");BX.Landing.Block.Node.Text.currentNode.onChange(true)},addTableButtons:function(e){var t=[];var n=[];var i=[];var a=this.getTableButtons();var s=[a[0],a[1],a[2],a[3]];var o=BX.Landing.Block.Node.Text.currentNode.node;var l=null;var d=false;var r=false;var c=false;var g=true;if(e.srcElement.classList.contains("landing-table")||e.srcElement.classList.contains("landing-table-col-dnd")){g=false}if(e.srcElement.classList.contains("landing-table-row-add")){r=true}if(e.srcElement.classList.contains("landing-table-col-add")){c=true}var h=[];var u=o.querySelectorAll(".landing-table");if(u.length>0){u.forEach((function(t){if(t.contains(e.srcElement)){l=t;return true}}))}a.forEach((function(t){t["options"]["srcElement"]=e.srcElement;t["options"]["node"]=o;t["options"]["table"]=l}));if(e.srcElement.classList.contains("landing-table-row-dnd")){i=e.srcElement.parentNode.children;i=Array.from(i);if(this.getAmountTableRows(l)>1){n=[0,1,2,3,4,5,6]}else{n=[0,1,2,3,4,5]}n.forEach((function(e){a[e]["options"]["target"]="row";a[e]["options"]["setTd"]=i;t.push(a[e])}))}if(e.srcElement.parentNode.classList.contains("landing-table-col-dnd")){var f=e.srcElement.parentElement.parentElement.childNodes;var L=Array.from(f);var T=[];L.forEach((function(e){if(e.nodeType===1){T.push(e)}}));var E=T.indexOf(e.srcElement.parentElement);var p=e.srcElement.parentElement.parentElement.parentElement.childNodes;p.forEach((function(e){if(e.nodeType===1){var t=[];e.childNodes.forEach((function(e){if(e.nodeType===1){t.push(e)}}));if(t[E]){i.push(t[E])}}}));if(this.getAmountTableCols(l)>1){n=[0,1,2,3,4,5,7]}else{n=[0,1,2,3,4,5]}n.forEach((function(e){a[e]["options"]["target"]="col";a[e]["options"]["setTd"]=i;t.push(a[e])}))}if(e.srcElement.classList.contains("landing-table-th-select-all")){var B;if(e.srcElement.classList.contains("landing-table-th-select-all-selected")){B=true;const s=e.srcElement.parentElement.parentElement.childNodes;s.forEach((function(e){e.childNodes.forEach((function(e){i.push(e)}))}));n=[0,1,2,3,4,5,8,9,10];n.forEach((function(e){a[e]["options"]["target"]="table";a[e]["options"]["setTd"]=i;t.push(a[e])}))}else{B=false;BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}}if(BX.Dom.hasClass(e.srcElement,"landing-table-td")||this.hasParentWithClass(e.srcElement,"landing-table-td")){i.push(e.srcElement);n=[3,2,1,0];n.forEach((function(e){a[e]["options"]["target"]="cell";a[e]["options"]["setTd"]=i;a[e].insertAfter="strikeThrough";t.push(a[e])}));d=true;h=["justifyLeft","justifyCenter","justifyRight","justifyFull","createTable","pasteTable"]}var I;let _=[];i.forEach((function(e){if(e.nodeType===1){I=undefined;if(e.classList.contains("text-left")){I="alignLeft"}if(e.classList.contains("text-center")){I="alignCenter"}if(e.classList.contains("text-right")){I="alignRight"}if(e.classList.contains("text-justify")){I="alignJustify"}_.push(I)}}));var b=0;var N=true;while(b<_.length&&N){if(b>0){if(_[b]!==_[b-1]){N=false}}b++}if(N){I=_[0]}else{I=undefined}if(I){s.forEach((function(e){if(e.id===I){e.layout.classList.add("landing-ui-active")}}))}if(t[0]&&t[1]&&t[2]&&t[3]){t[0]["options"]["alignButtons"]=s;t[1]["options"]["alignButtons"]=s;t[2]["options"]["alignButtons"]=s;t[3]["options"]["alignButtons"]=s}if(!this.manifest.textOnly){if(g){if(!r&&!c&&l){if(!d){if(B===false){BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}else{BX.Landing.UI.Panel.EditorPanel.getInstance().show(l.parentNode,null,t,true)}}else{BX.Landing.UI.Panel.EditorPanel.getInstance().show(l.parentNode,null,t,true,h)}}}else{BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}}},hasParentWithClass:function(e,t){let n=e.parentNode;while(n!==null){if(n.classList&&BX.Dom.hasClass(n,t)){return true}n=n.parentNode}return false},getChangeTagButton:function(){if(!this.changeTagButton){this.changeTagButton=new BX.Landing.UI.Button.ChangeTag("changeTag",{html:'<span class="landing-ui-icon-editor-'+this.node.nodeName.toLowerCase()+'"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_CHANGE_TAG")},onChange:this.onChangeTag.bind(this)})}this.changeTagButton.insertAfter="unlink";this.changeTagButton.activateItem(this.node.nodeName);return this.changeTagButton},getTableButtons:function(){this.buttons=[];this.buttons.push(new BX.Landing.UI.Button.AlignTable("alignLeft",{html:'<span class="landing-ui-icon-editor-left"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_LEFT")}}),new BX.Landing.UI.Button.AlignTable("alignCenter",{html:'<span class="landing-ui-icon-editor-center"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_CENTER")}}),new BX.Landing.UI.Button.AlignTable("alignRight",{html:'<span class="landing-ui-icon-editor-right"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_RIGHT")}}),new BX.Landing.UI.Button.AlignTable("alignJustify",{html:'<span class="landing-ui-icon-editor-justify"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_ALIGN_JUSTIFY")}}),new BX.Landing.UI.Button.ColorAction("tableTextColor",{text:BX.Landing.Loc.getMessage("EDITOR_ACTION_SET_FORE_COLOR"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_COLOR")}}),new BX.Landing.UI.Button.ColorAction("tableBgColor",{html:'<i class="landing-ui-icon-editor-fill-color"></i>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_CELL_BG")}}),new BX.Landing.UI.Button.DeleteElementTable("deleteRow",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DELETE_ROW_TABLE")}}),new BX.Landing.UI.Button.DeleteElementTable("deleteCol",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_DELETE_COL_TABLE")}}),new BX.Landing.UI.Button.StyleTable("styleTable",{html:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_STYLE")+'<i class="fas fa-chevron-down g-ml-8"></i>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_STYLE")}}),new BX.Landing.UI.Button.CopyTable("copyTable",{text:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_COPY"),attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_COPY")}}),new BX.Landing.UI.Button.DeleteTable("deleteTable",{html:'<span class="landing-ui-icon-editor-delete"></span>',attrs:{title:BX.Landing.Loc.getMessage("LANDING_TITLE_OF_EDITOR_ACTION_TABLE_DELETE")}}));return this.buttons},onChangeTag:function(e,t){this.node=n(this.node,e);this.node.addEventListener("mousedown",this.onMousedown);this.node.addEventListener("click",this.onClick);this.node.addEventListener("paste",this.onPaste);this.node.addEventListener("drop",this.onDrop);this.node.addEventListener("input",this.onInput);this.node.addEventListener("keydown",this.onInput);if(!this.getField().isEditable()&&!t){this.disableEdit();this.enableEdit()}var i={};i[this.selector]=e;if(!t){this.changeOptionsHandler(i).then((()=>{BX.Landing.History.getInstance().push()}))}},getAmountTableCols:function(e){return e.querySelectorAll(".landing-table-col-dnd").length},getAmountTableRows:function(e){return e.querySelectorAll(".landing-table-row-dnd").length},prepareTable:function(e){var t=["table-selected-all","landing-table-th-select-all-selected","landing-table-cell-selected","landing-table-row-selected","landing-table-th-selected","landing-table-th-selected-cell","landing-table-th-selected-top","landing-table-th-selected-x","landing-table-tr-selected-left","landing-table-tr-selected-y","landing-table-col-selected","landing-table-tr-selected","table-selected-all-right","table-selected-all-bottom"];t.forEach((function(t){e.querySelectorAll("."+t).forEach((function(e){e.classList.remove(t)}))}));return e},onBackspaceDown:function(e){var t=window.getSelection();var n=t.getRangeAt(0).startOffset;if(n===0){var i=t.focusNode;if(!BX.Type.isNil(i)&&i.nodeType!==3){if(i.firstChild.nodeType===3&&i.firstChild.firstChild.nodeType===3){i=i.firstChild.firstChild}else if(i.firstChild.nodeType!==3){i=i.firstChild}else{i=null}}if(i){var a=i.parentNode;var s=["BLOCKQUOTE","UL"];if(a&&s.includes(a.nodeName)){var o=document.createElement("div");o.append(i);a.append(o)}var l=i.parentNode.parentNode;while(l&&!s.includes(l.nodeName)){l=l.parentNode}if(l&&l.childNodes.length===1){l.after(i.parentNode);l.remove();e.preventDefault()}}}},isLinkPasted:function(e){var t=/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/;return!!e.match(t)},prepareToLink:function(e){return"<a class='g-bg-transparent' href='"+e+"' target='_blank'> "+e+" </a>"}}})();
//# sourceMappingURL=text.map.js